{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4d9d5ac4-dc84-4e76-9f20-1db896dea731",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      1      \n",
      "     1 1     \n",
      "    1 2 1    \n",
      "   1 3 3 1   \n",
      "  1 4 6 4 1  \n",
      "1 5 10 10 5 1\n"
     ]
    }
   ],
   "source": [
    "def display(triangle):\n",
    "    max_length = len(' '.join(str(num)for num in triangle[-1]).center(len(triangle)*2))\n",
    "    for row in triangle:\n",
    "        row_str =' '.join(str(num)for num in row).center(len(triangle) * 2)\n",
    "        print(row_str.center(max_length))\n",
    "def generate(n):\n",
    "    triangle = []\n",
    "    for i in range(n):\n",
    "        row = [1] * (i+1)\n",
    "        triangle.append(row)\n",
    "        for j in range(1,i):\n",
    "            row[j] = triangle[i-1][j-1] + triangle[i-1][j]\n",
    "    return triangle\n",
    "display(generate(6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "65af8740-65e5-442a-9337-d3d3826b43eb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
